import axios from './http';
import { HttpResponse } from '../types/HttpResponse';

interface Url {
  [key: string]: string;
}
const url: Url = {
  getQList: '/q/list/get',
  exportQ: '/q/download',
  getRecycledQList: '/q/recycledList/get',
  deleteQ: '/q/delete',
  restoreQ: '/q/restore',
  copyQ: '/q/copy',
  // 保存问卷
  saveQ: '/q/save',
  //回收站清空
  clearRecycledQList: '/q/recycledList/clear',
  // 编辑时获取问卷
  getQ: '/q/get',
  // 提交问卷（public）
  submitQ: '/q/submit',
  // 获取问卷（public）
  obtainQ: '/q/obtain',
  // 开启问卷
  openQ: '/q/open',
  // 关闭问卷
  closeQ: '/q/close',
  //页面结果信息获取
  getResult: '/q/result/get',
  // 发布问卷（包括设计）
  releaseQ: '/q/release',
  // 获取问卷设计
  designQ: '/q/design',
  // 统计分析
  analyzeQ: '/q/analysis/all',
  // 交叉分析
  analyzeQX: '/q/analysis/cross',
  // 获取问题id集
  getIds: '/q/analysis/choose',
  //删除答卷
  deleteAnswer: '/q/analysis/delete',
  // 填写情况总览
  overviewQ: '/q/analysis/overview',
  // 获取某个人的填写情况
  answerQ: '/q/answer',
  //根据题号获取分析文件路径和文件名
  getAnalysis: '/q/analysis/fillin',
  //交叉分析
  getAnalysisX: '/q/analysis/cross',
  //实时数据
  getRT: '/q/getNum',
  //实时数据
  verifyPassword: '/q/lock/verify',

  //随机码
  getCode: '/q/code/get',
  changeCode: '/q/code/change',

  //获取填空题数据
  getFdata: '/q/analysis/fillin',
};

//封装接口方法
export class Ques {
  //根据题号获取统计数据
  static async getAnalysis(params:{questionId: number}): Promise<HttpResponse> {
    return axios(url.getAnalysis, {
      method: 'get',
      responseType: 'json',
      params: params,
    });
  }
  //交叉分析
  static async getAnalysisX(data:{id: number,x: number,y: number}): Promise<HttpResponse> {
    return axios(url.getAnalysisX, {
      method: 'post',
      responseType: 'json',
      data: data
    });
  }
  //获取问卷列表
  static async getQList(): Promise<HttpResponse> {
    return axios(url.getQList, {
      method: 'get',
      responseType: 'json',
    });
  }
 
  //获取回收站中的列表
  static async getRecycledQList(): Promise<HttpResponse> {
    return axios(url.getRecycledQList, {
      method: 'get',
      responseType: 'json',
    });
  }
  //清空回收站
  static async clearRecycledQList(): Promise<HttpResponse> {
    return axios(url.clearRecycledQList, {
      method: 'get',
      responseType: 'json',
    });
  }
  //删除问卷列表的问卷
  static async deleteAnswer(data: object): Promise<HttpResponse> {
    return axios(url.deleteAnswer, {
      method: 'post',
      responseType: 'json',
      data: data,
    });
  }
  //删除问卷列表的问卷
  static async deleteQ(data: { id: number }): Promise<HttpResponse> {
    return axios(url.deleteQ, {
      method: 'post',
      responseType: 'json',
      data: data,
    });
  }
  //恢复回收站中的列表
  static async restoreQ(data: { id: number }): Promise<HttpResponse> {
    return axios(url.restoreQ, {
      method: 'post',
      responseType: 'json',
      data: data,
    });
  }
  //复制问卷
  static async copyQ(data: {
    //被复制的问卷的ID
    id: number;
    title: string;
  }): Promise<HttpResponse> {
    return axios(url.copyQ, {
      method: 'post',
      responseType: 'json',
      data: data,
    });
  }
  //保存问卷（新建、修改）
  static async saveQ(data: {
    id: number;
    title: string;
    note: string;
    qStatus: number;
    version: string;
    amount: number;
    showIndex: boolean;
    content: [
      type: string,
      id: string,
      title: string,
      remark: string,
      required: boolean,
      more: Object
    ];
  }): Promise<HttpResponse> {
    return axios(url.saveQ, {
      method: 'post',
      responseType: 'json',
      data: data,
    });
  }
  //获取问卷（编辑问卷）
  static async getQ(params: { id: string }): Promise<HttpResponse> {
    return axios(url.getQ, {
      method: 'get',
      responseType: 'json',
      params: params,
    });
  }
  // 获取公开问卷
  static async obtainQ(params: {
    id: string;
    randomCode: string;
  }): Promise<HttpResponse> {
    return axios(url.obtainQ, {
      method: 'get',
      responseType: 'json',
      params: params,
    });
  }
  //提交问卷 （公开问卷收集）
  static async submitQ(data: {
    id: number;
    title: string;
    ip: number;
    start: string;
    end: string;
    ddl: string;
    content: [type: string, id: string, more: Object];
  }): Promise<HttpResponse> {
    return axios(url.submitQ, {
      method: 'post',
      responseType: 'json',
      data: data,
    });
  }
  // 开启问卷
  static async openQ(params: { id: string }): Promise<HttpResponse> {
    return axios(url.openQ, {
      method: 'get',
      responseType: 'json',
      params: params,
    });
  }
  // 关闭问卷
  static async closeQ(params: { id: string }): Promise<HttpResponse> {
    return axios(url.closeQ, {
      method: 'get',
      responseType: 'json',
      params: params,
    });
  }

  // 发布问卷设计
  static async releaseQ(data: { id: string }): Promise<HttpResponse> {
    return axios(url.releaseQ, {
      method: 'post',
      responseType: 'json',
      data: data,
    });
  }
  // 获取问卷设计
  static async designQ(params: { id: string }): Promise<HttpResponse> {
    return axios(url.designQ, {
      method: 'get',
      responseType: 'json',
      params: params,
    });
  }

  // 获取随机码
  static async getCode(params: { id: string }): Promise<HttpResponse> {
    return axios(url.getCode, {
      method: 'get',
      responseType: 'json',
      params: params,
    });
  }
  // 重置随机码
  static async changeCode(data: { id: string }): Promise<HttpResponse> {
    return axios(url.changeCode, {
      method: 'post',
      responseType: 'json',
      data: data,
    });
  }
  //答卷数据
  static async overviewQ(data: { id: number }): Promise<HttpResponse> {
    return axios(url.overviewQ, {
      method: 'post',
      responseType: 'json',
      data: data,
    });
  }
   // 发布问卷设计
   static async getResult(data: { id: number }): Promise<HttpResponse> {
    return axios(url.getResult, {
      method: 'post',
      responseType: 'json',
      data: data,
    });
  }
  //答卷数据
  static async answerQ(params: { aId: number }): Promise<HttpResponse> {
    return axios(url.answerQ, {
      method: 'get',
      responseType: 'json',
      params: params,
    });
  }
  //页面结果信息获取
  
  //获取题目集
  static async getIds(params: { id: number }): Promise<HttpResponse> {
    return axios(url.getIds, {
      method: 'get',
      responseType: 'json',
      params: params,
    });
  }
  //图表分析
  static async analyzeQ(params: { id: number }): Promise<HttpResponse> {
    return axios(url.analyzeQ, {
      method: 'get',
      responseType: 'json',
      params: params,
    });
  }

  //交叉分析
  // static async analyzeQX(params: {
  //   id: number;
  //   x: any;
  //   y: any;
  // }): Promise<HttpResponse> {
  //   return axios(url.analyzeQX, {
  //     method: 'get',
  //     responseType: 'json',
  //     params: params,
  //   });
  // }
  static async analyzeQX(data: {
    id: number;
    x: any;
    y: any;
  }): Promise<HttpResponse> {
    return axios(url.analyzeQX, {
      method: 'post',
      responseType: 'json',
      data: data,
    });
  }

  // 获取实时数据
  static async getRT(params: { id: number }): Promise<HttpResponse> {
    return axios(url.getRT, {
      method: 'get',
      responseType: 'json',
      params: params,
    });
  }
  // 验证密码
  static async verifyPassword(params: {
    id: number;
    password: string;
  }): Promise<HttpResponse> {
    return axios(url.verifyPassword, {
      method: 'get',
      responseType: 'json',
      params: params,
    });
  }
  //获取填空题数据
  static async getFdata(params: { questionId: number }): Promise<HttpResponse> {
    return axios(url.getFdata, {
      method: 'get',
      responseType: 'json',
      params: params,
    });
  }
}
